import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["type"];

/**
 * financialCodeService - 财务代码设置
 * @date: 2019-3-7
 */
import { getCurrentOrganizationId, parseParameters, filterNullValueObject } from 'utils/utils';
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
var organizationId = getCurrentOrganizationId();
/**
 * 查询财务代码设置
 * @param {object} param - 查询参数对象
 */

export function queryList(_x) {
  return _queryList.apply(this, arguments);
}
/**
 * 保存创建的财务代码设置
 * @param {object} param - 新增的财务代码
 */

function _queryList() {
  _queryList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var _filterNullValueObjec, type, rest;

    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _filterNullValueObjec = filterNullValueObject(parseParameters(params)), type = _filterNullValueObjec.type, rest = _objectWithoutProperties(_filterNullValueObjec, _excluded);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/fin-codes"), {
              method: 'GET',
              query: _objectSpread(_objectSpread({}, rest), {}, {
                type: (type || []).join(',')
              })
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryList.apply(this, arguments);
}

export function saveCreate(_x2) {
  return _saveCreate.apply(this, arguments);
}
/**
 * 更新财务代码设置
 * @param {object} params - 修改的财务代码
 */

function _saveCreate() {
  _saveCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/fin-codes"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _saveCreate.apply(this, arguments);
}

export function saveUpdate(_x3) {
  return _saveUpdate.apply(this, arguments);
}

function _saveUpdate() {
  _saveUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/fin-codes"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _saveUpdate.apply(this, arguments);
}